package demo.bocweb.com.sdk.util;

import android.app.Activity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import demo.bocweb.com.sdk.R;

/**
 * toolbar工具类
 * Created by zhelun on 2018/2/5.
 */

public class ToolbarHelper {
    public static Toolbar init(Activity activity, int title, int resId, View.OnClickListener onClickListener) {
        Toolbar toolbar = activity.findViewById(R.id.toolbar);
        TextView tvTitle = activity.findViewById(R.id.tv_title);
        tvTitle.setText(title);
        toolbar.setNavigationIcon(resId);
        toolbar.setNavigationOnClickListener(onClickListener);
        return toolbar;
    }

    public static Toolbar init(Activity activity, String title, int resId, View.OnClickListener onClickListener) {
        Toolbar toolbar = activity.findViewById(R.id.toolbar);
        TextView tvTitle = activity.findViewById(R.id.tv_title);
        tvTitle.setText(title);
        toolbar.setNavigationIcon(resId);
        toolbar.setNavigationOnClickListener(onClickListener);
        return toolbar;
    }

    public static Toolbar init(Activity activity, int title, int resId, View.OnClickListener onClickListener, String menuTxt, View.OnClickListener menuOnclick) {
        Toolbar toolbar = activity.findViewById(R.id.toolbar);
        TextView tvTitle = activity.findViewById(R.id.tv_title);
        TextView tvMenu = activity.findViewById(R.id.tv_menu);
        tvMenu.setVisibility(View.VISIBLE);
        tvTitle.setText(title);
        tvMenu.setText(menuTxt);
        tvMenu.setOnClickListener(menuOnclick);
        toolbar.setNavigationIcon(resId);
        toolbar.setNavigationOnClickListener(onClickListener);
        return toolbar;
    }

    public static Toolbar init(Activity activity, int title, int resId, View.OnClickListener onClickListener, int menuIcon, View.OnClickListener menuOnclick) {
        Toolbar toolbar = activity.findViewById(R.id.toolbar);
        TextView tvTitle = activity.findViewById(R.id.tv_title);
        ImageView ivMenu = activity.findViewById(R.id.iv_menu);
        ivMenu.setVisibility(View.VISIBLE);
        tvTitle.setText(title);
        ivMenu.setImageResource(menuIcon);
        ivMenu.setOnClickListener(menuOnclick);
        toolbar.setNavigationIcon(resId);
        toolbar.setNavigationOnClickListener(onClickListener);
        return toolbar;
    }
}
